//https://leetcode.cn/problems/delete-and-earn/

class Solution {
public:
    int deleteAndEarn(vector<int>& nums) {
        int n = nums.size();
        vector<int> arr(10001);
        for (int i = 0; i < n; i++)
        {
            arr[nums[i]] += nums[i];
        }
        vector<int> dpf(10001);
        auto dpg = dpf;

        for (int i = 1; i < 10001; i++)
        {
            dpf[i] = dpg[i - 1] + arr[i];
            dpg[i] = max(dpf[i - 1], dpg[i - 1]);
        }

        return max(dpf[10001 - 1], dpg[10001 - 1]);





    }
};